package com.zxy.ziems.server.message.impl;

import com.alibaba.fastjson.JSON;
import com.zxy.ziems.server.message.MessageService;
import com.zxy.ziems.server.websocket.CustomMessage;
import com.zxy.ziems.server.websocket.MyCustomWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MyCustomWebSocketHandler myCustomWebSocketHandler;
    @Async
    @Override
    public void sendWebSocketMessage(CustomMessage message) {
        TextMessage textMessage = new TextMessage(JSON.toJSONString(message));
        myCustomWebSocketHandler.sendMessageToAllUser(textMessage);
    }
}
